<template>
  <div>
    <div class="loginContentBox" id="loginContentBox" :style="{ backgroundImage: 'url(' + (datarend.type == 'picture' ? datarend.picture_url : '') + ')' }">
      <videoBase2 v-if="datarend.type == 'video'" :video="video" />
      <div class="loginContent">
        <div class="loginImg"><img :src="datarend.sys_logo" /></div>
        <div class="Logintitle">{{ datarend.sys_name }}</div>
        <el-form :model="form" class="loginForm" ref="ruleForm" @keyup.enter.native="onSubmit">
          <el-form-item>
            <el-input class="loginInput" placeholder="用户账号" v-model="form.username" clearable>
              <i class="icon-user el-input__icon iconfont fontsize24 " slot="prefix"></i>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-input placeholder="输入密码" class="loginInput" v-model="form.password" type="password" clearable>
              <i class="icon-password el-input__icon iconfont fontsize24 " slot="prefix"></i>
            </el-input>
          </el-form-item>
          <el-form-item><el-button type="primary" round class="loginBtn wd100" @click="onSubmit">登录</el-button></el-form-item>
        </el-form>
        <div class="footerDescribe">
          <div class="leftTest">技术支持:</div>
          &nbsp;&nbsp;
          <img :src="datarend.sys_ver_pic" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getWindows } from '../../utils/window.js';
import videoBase2 from '@/components/videoBase2';
import { loginIndex, userLoginJson, runGzyq, btnCodeGetSkin, LeftMenuColor } from '../../api/config.js';
import { add2Cache, getFromCache, removeFromCache } from '../../utils/cache.js';
export default {
  computed: {},
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      video: {
        video_url: '', //视频地址
        poster: '' //封面地址
      },
      rules: {
        // username: [{ required: true, message: '请输入登录名', trigger: 'blur' }],
        // region: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
        // date1: [{ type: 'date', required: true, message: '请选择日期', trigger: 'change' }],
        // password: [{ required: true, message: '请输入登录密码', trigger: 'change' }],
        // desc: [{ required: true, message: '请填写活动形式', trigger: 'blur' }]
      },
      datarend: ''
    };
  },
  mounted() {
    getWindows('loginContentBox');
    window.onresize = function() {
      getWindows('loginContentBox');
    };
    // this.initVideo();
  },
  created() {
    this.loginRend();
    var lett = this;
    document.onkeydown = function(e) {
      var key = window.event.keyCode;
      if (key == 13) {
        lett.onSubmit();
      }
    };
  },
  components: {
    videoBase2
  },
  methods: {
    loginRend() {
      let that = this;
      let parmas = {};
      that.$post(loginIndex).then(response => {
        this.datarend = response.obj;
        if (this.datarend.type == 'video') {
          this.video.video_url = this.datarend.video_url;
          this.video.poster = this.datarend.video_cover_url;
        }
      });
    },
    onSubmit() {
      let that = this;
      let parmas = {};
      parmas.username = that.form.username;
      parmas.password = that.form.password;
      const backUrl = this.$route.query.backurl;
      if (backUrl) {
        parmas.backurl = backUrl;
      }
      that.$post(userLoginJson, parmas).then(response => {
        if (response.code == 'fail') {
          that.$message({
            message: response.message,
            type: 'warning'
          });
          return;
        }
        if (backUrl) {
          location.href = response.data.redirctUrl;
          return;
        }
        removeFromCache('myUserinfo');
        add2Cache('__JID__', response.data.JID);
        let userInfo = JSON.stringify(response.data.TU_ENV);
        add2Cache('userInfo', userInfo);
        if (!response.data.needChPwd) {
          //  let par={};
          //  par.user_prn=response.data.TU_ENV.env$user_prn;
          // that.$post(LeftMenuColor, par).then(res => {
          //      if (response.status === false) {
          //      	that.$message.error(res.error[0]);
          //      	return;
          //      }
          //     add2Cache('skin',res.obj.blueSkin);
          that.$router.push('/home');
          // })
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
